﻿using Sw.Hospital.HealthExaminationSystem.Application.BasicDictionary.Dto;
using Sw.Hospital.HealthExaminationSystem.Common.Bases;
using Sw.Hospital.HealthExaminationSystem.Common.Enums;
using Sw.Hospital.HealthExaminationSystem.Common.Helpers;
using Sw.Hospital.HealthExaminationSystem.Common.UserCache;
using Sw.Hospital.HealthExaminationSystem.UserSettings.BasicDictionary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sw.Hospital.HealthExaminationSystem.Comm
{
    
 
    public partial class frmMess : UserBaseForm
    {
        public string mb = "";
        public frmMess()
        {
            InitializeComponent();
        }

        private void frmMess_Load(object sender, EventArgs e)
        {
            var basicDictionaries = DefinedCacheHelper.GetBasicDictionary().Where(p => p.Type == BasicDictionaryType.ShortModle.ToString()).ToList();


            gridControl1.DataSource = basicDictionaries;
        }

        private void labelControl1_Click(object sender, EventArgs e)
        {

            int insertIndex = richTextBox1.SelectionStart;
            string bq = "【姓名】";
            richTextBox1.Text = richTextBox1.Text.Insert(insertIndex, bq);
            richTextBox1.SelectionStart = insertIndex + bq.Length;
            richTextBox1.SelectionLength = 0;
            
        }

        private void labelControl2_Click(object sender, EventArgs e)
        {
            int insertIndex = richTextBox1.SelectionStart;
            string bq = "【性别】";
            richTextBox1.Text = richTextBox1.Text.Insert(insertIndex, bq);
            richTextBox1.SelectionStart = insertIndex + bq.Length;
            richTextBox1.SelectionLength = 0;
        }

        private void labelControl3_Click(object sender, EventArgs e)
        {
            int insertIndex = richTextBox1.SelectionStart;
            string bq = "【体检号】";
            richTextBox1.Text = richTextBox1.Text.Insert(insertIndex, bq);
            richTextBox1.SelectionStart = insertIndex + bq.Length;
            richTextBox1.SelectionLength = 0;
        }

        private void labelControl4_Click(object sender, EventArgs e)
        {
            int insertIndex = richTextBox1.SelectionStart;
            string bq = "【阳性项目】";
            richTextBox1.Text = richTextBox1.Text.Insert(insertIndex, bq);
            richTextBox1.SelectionStart = insertIndex + bq.Length;
            richTextBox1.SelectionLength = 0;
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(richTextBox1.Text))
            {
                MessageBox.Show("录入短信模板");
                return;
            }
            mb = richTextBox1.Text;
            this.DialogResult = DialogResult.OK;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            using (var frm = new BasicDictionaryEditor(BasicDictionaryType.ShortModle, richTextBox1.Text))
            {
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    var  basicDictionaries = DefinedCacheHelper.GetBasicDictionary().Where(p=>p.Type== BasicDictionaryType.ShortModle.ToString()).ToList();


                    gridControl1.DataSource = basicDictionaries;
                }
            }
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {

        }

        private void gridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
        {
            var dto = gridControl1.GetFocusedRowDto<BasicDictionaryDto>();
            if (dto == null)
                return;
            richTextBox1.Text = dto.Remarks;
        }
    }
}
